package com.ninth_group.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
import com.ninth_group.utils.ParseLocalTimeUtil;


import java.sql.ResultSet;
import java.sql.SQLException;
import java.time.LocalTime;

public class CityVO {
    private String cityId;
    private int currentTemp;
    private String province;
    private String city;
    private String uv;
    private int pm25;
    @JsonSerialize(using = LocalTimeSerializer.class)
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
    private LocalTime sunsetTime;
    private String weather;
    @JsonSerialize(using = LocalTimeSerializer.class)
    @JsonDeserialize(using = LocalTimeDeserializer.class)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm")
    private LocalTime sunriseTime;
    private String humidity;
    private int tempMax;
    private int tempMin;
    private String windDirection; // 风向
    private int windScale; // 风力等级

    public static CityVO mapRow(ResultSet rs) throws SQLException {
        CityVO city = new CityVO();
        city.setCityId(rs.getString("city_id"));
        city.setCurrentTemp(rs.getInt("current_temp"));
        city.setProvince(rs.getString("province"));
        city.setCity(rs.getString("city"));
        city.setUv(rs.getString("uv"));
        city.setPm25(rs.getInt("pm25"));
        city.setSunsetTime(
                ParseLocalTimeUtil.parseToLocalTime(rs.getString("sunset_time")));
        city.setWeather(rs.getString("weather"));
        city.setSunriseTime(
                ParseLocalTimeUtil.parseToLocalTime(rs.getString("sunrise_time")));
        city.setHumidity(rs.getString("humidity"));
        city.setTempMax(Integer.parseInt(rs.getString("temp_max")));
        city.setTempMin(Integer.parseInt(rs.getString("temp_min")));
        city.setWindDirection(rs.getString("wind_direction"));
        city.setWindScale(rs.getInt("wind_scale"));
        return city;
    }

    public CityVO() {
    }

    public CityVO(String cityId, int currentTemp, String province,
                  String city, String uv, int pm25, LocalTime sunsetTime,
                  String weather, LocalTime sunriseTime, String humidity,
                  int tempMax, int tempMin, String windDirection, int windScale) {
        this.cityId = cityId;
        this.currentTemp = currentTemp;
        this.province = province;
        this.city = city;
        this.uv = uv;
        this.pm25 = pm25;
        this.sunsetTime = sunsetTime;
        this.weather = weather;
        this.sunriseTime = sunriseTime;
        this.humidity = humidity;
        this.tempMax = tempMax;
        this.tempMin = tempMin;
        this.windDirection = windDirection;
        this.windScale = windScale;
    }

    @Override
    public String toString() {
        return "CityVO{" +
                "cityId='" + cityId + '\'' +
                ", currentTemp=" + currentTemp +
                ", province='" + province + '\'' +
                ", city='" + city + '\'' +
                ", uv='" + uv + '\'' +
                ", pm25=" + pm25 +
                ", sunsetTime=" + sunsetTime +
                ", weather='" + weather + '\'' +
                ", sunriseTime=" + sunriseTime +
                ", humidity='" + humidity + '\'' +
                ", tempMax=" + tempMax +
                ", tempMin=" + tempMin +
                ", windDirection='" + windDirection + '\'' +
                ", windScale=" + windScale +
                '}';
    }

    public String getCityId() {
        return cityId;
    }

    public void setCityId(String cityId) {
        this.cityId = cityId;
    }

    public int getCurrentTemp() {
        return currentTemp;
    }

    public void setCurrentTemp(int currentTemp) {
        this.currentTemp = currentTemp;
    }

    public String getProvince() {
        return province;
    }

    public void setProvince(String province) {
        this.province = province;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getUv() {
        return uv;
    }

    public void setUv(String uv) {
        this.uv = uv;
    }

    public int getPm25() {
        return pm25;
    }

    public void setPm25(int pm25) {
        this.pm25 = pm25;
    }

    public LocalTime getSunsetTime() {
        return sunsetTime;
    }

    public void setSunsetTime(LocalTime sunsetTime) {
        this.sunsetTime = sunsetTime;
    }

    public String getWeather() {
        return weather;
    }

    public void setWeather(String weather) {
        this.weather = weather;
    }

    public LocalTime getSunriseTime() {
        return sunriseTime;
    }

    public void setSunriseTime(LocalTime sunriseTime) {
        this.sunriseTime = sunriseTime;
    }

    public String getHumidity() {
        return humidity;
    }

    public void setHumidity(String humidity) {
        this.humidity = humidity;
    }

    public int getTempMax() {
        return tempMax;
    }

    public void setTempMax(int tempMax) {
        this.tempMax = tempMax;
    }

    public int getTempMin() {
        return tempMin;
    }

    public void setTempMin(int tempMin) {
        this.tempMin = tempMin;
    }

    public String getWindDirection() {
        return windDirection;
    }

    public void setWindDirection(String windDirection) {
        this.windDirection = windDirection;
    }

    public int getWindScale() {
        return windScale;
    }

    public void setWindScale(int windScale) {
        this.windScale = windScale;
    }
}
